<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>tooltipster插件使用-ajax加载内容</title>
        <link rel="stylesheet" href="css/tooltipster.bundle.css" />
        <style>
            .tooltip_template { display:none;width: 600px;height: 400px;background-color: #ccc; }
        </style>
    </head>
    <body>
        <!-- <img src="my-image.png" class="tooltip" title="This is my image's tooltip message!" /> -->

        <span class="tooltip" data-tooltip-content="#tooltip-content">html提示框</span>
        <div id="tooltips-template" class="tooltip_template"><span id="tooltip-content" class="tooltip-content"><img src="../img/tourism1.png" alt="图片" /><br /><strong>自定义html提示框</strong></span></div>
        <script src="http://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
        <script src="js/tooltipster.bundle.min.js"></script>
        <script>
        // $(".tooltip").tooltipster();
        // $('.tooltip').tooltipster({
        //    animation: 'fade',
        //    delay: 200,
        //    theme: 'tooltipster-punk',
        //    trigger: 'hover'
        // });
        $('.tooltip').tooltipster({
            content: 'Loading...',
            // 'instance' is basically the tooltip. More details in the "Object-oriented Tooltipster" section.
            functionBefore: function(instance, helper) {
                
                var $origin = $(helper.origin);
                
                // we set a variable so the data is only loaded once via Ajax, not every time the tooltip opens
                if ($origin.data('loaded') !== true) {
                    $.getJSON('data/tooltips.json',function(data){
                        console.log('data',data);
                        instance.content(data.title);
                        $origin.data('loaded', true);
                    });
                    // $.get('http://example.com/ajax.php', function(data) {

                    //     // call the 'content' method to update the content of our tooltip with the returned data.
                    //     // note: this content update will trigger an update animation (see the updateAnimation option)
                    //     instance.content(data);

                    //     // to remember that the data has been loaded
                    //     $origin.data('loaded', true);
                    // });
                }
            }
        });
        </script>
    </body>
</html>